// pages/components/file/nav/nav.js
Component({

  data: {
    hideModal: true, //模态框的状态  true-隐藏  false-显示
    animationData: {}, 
    btn: null,    //用来记录点击的导航栏的按钮类型
    sortBtn:false,  //记录排序规则按钮的值
    edit:false
  },
  properties: {
    isFolder:Boolean
  },
  methods: {
    // 显示遮罩层
    showModal: function(e) {
      var that = this;
      that.setData({
        hideModal: false,
        btn: e.currentTarget.dataset.btn
      })
      var animation = wx.createAnimation({
        duration: 100, //动画的持续时间 默认400ms   数值越大，动画越慢   数值越小，动画越快
        timingFunction: 'ease', //动画的效果 默认值是linear
      })
      this.animation = animation
      setTimeout(function() {
        that.fadeIn(); //调用显示动画
      }, 100)
    },
    // 隐藏遮罩层
    hideModal: function() {
      var that = this;
      var animation = wx.createAnimation({
        duration: 400, //动画的持续时间 默认400ms   数值越大，动画越慢   数值越小，动画越快
        timingFunction: 'ease', //动画的效果 默认值是linear
      })
      this.animation = animation
      that.fadeDown(); //调用隐藏动画   
      setTimeout(function() {
        that.setData({
          hideModal: true
        })
      }, 200) //先执行下滑动画，再隐藏模块
    },
    //动画集
    fadeIn: function() {  //进入动画
      this.animation.translateY(0).step()
      this.setData({
        animationData: this.animation.export() //动画实例的export方法导出动画数据传递给组件的animation属性
      })
    },
    fadeDown: function () { //退出动画
      this.animation.translateY(300).step()
      this.setData({
        animationData: this.animation.export(),
      })
    },
    
    // 点击排序弹框的排序规则按钮处理函数
    getSort(e){
      let sort = e.currentTarget.dataset.sort
      let sortid = e.currentTarget.dataset.sortid
      let sortBtn = {sort: sortid,status:true}
      this.setData({
        sortBtn
      })
    // 调用隐藏弹框模块
      this.hideModal()
    },
    getSearchKey(e){
      console.log(e.detail.value)
      this.hideModal()
    },
    uplate(){
       this.setData({
         edit:!this.data.edit
       })
      this.triggerEvent('myevent', { edit: this.data.edit });
    },
    cancelEdit(){
      this.setData({
        edit: false
      })
      this.triggerEvent('myevent', { edit: false });
    }
  }
})